package com.wxd.woff.graphics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @ClassName: AbstractWoffImage
 * @author: Wang Xindong
 * @date: 2018年9月7日 下午2:41:09
 * @email: wangxindong@travelsky.com
 * @Copyright: Copyright (c) 2018. All rights reserved.
 */
public abstract class AbstractWoffImage implements WoffImage {

    protected static final Logger LOGGER = LoggerFactory.getLogger(SampledImageReader.class);
    private static final int DEFAULT_TYPE = BufferedImage.TYPE_BYTE_GRAY;

    private String DEFAULT_FORMATNAME = "png";
    private String formatName = DEFAULT_FORMATNAME;

    @Override
    public BufferedImage getImage() throws IOException {
        BufferedImage image = new BufferedImage(getWidth(), getHeight(), DEFAULT_TYPE);
        return image;
    }

    @Override
    public BufferedImage getImage(int type) throws IOException {
        BufferedImage image = new BufferedImage(getWidth(), getHeight(), type);
        return image;
    }

    @Override
    public void write(BufferedImage image, OutputStream out) throws IOException {
        write(image, formatName, out);
    }

    @Override
    public Graphics2D getGraphics2D() throws IOException {
        BufferedImage image = getImage();
        return image.createGraphics();
    }
}
